package com.lebang.controller.api.bus;

import com.lebang.common.Require;
import com.lebang.feign.bus.MemberBussDestinationRecordFegin;
import com.lebang.model.RequestUserInfo;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 公交用户目的地记录
 *
 * @Author: ljx
 * @Date: 2020/12/18
 */
@Api(tags = "公交用户目的地记录")
@RestController
@RequestMapping("/api/destination")
public class MemberBussDestinationRecordApi {
    @Autowired
    private MemberBussDestinationRecordFegin fegin;

    @Require
    @ApiOperation("目的地记录")
    @PostMapping("/get")
    public JsonData get(HttpServletRequest request, @ApiParam(name = "城市id") @RequestParam("cityId") String cityId){
        if (cityId == null){
            return Callback.fail("fail","查询失败");
        }
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return fegin.get(userInfo,cityId);
    }

    @Require
    @ApiOperation("添加目的地记录")
    @PostMapping("/add")
    public JsonData add(HttpServletRequest request,
                        @ApiParam(name = "位置") @RequestParam("site") String site,
                        @ApiParam(name = "信息") @RequestParam("message") String message,
                        @ApiParam(name = "类型") @RequestParam("type") Integer type,
                        @ApiParam(name = "标识") @RequestParam("poiId") String poiId,
                        @ApiParam(name = "城市id") @RequestParam("cityId") String cityId){
        if (cityId == null){
            return Callback.fail("fail","添加失败");
        }
        if (message == null || type == null || poiId == null){
            return Callback.fail("fail","添加失败");
        }
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return fegin.add(userInfo,site,message,type,poiId,cityId);
    }

    @Require
    @ApiOperation("删除目的地记录")
    @PostMapping("/del")
    public JsonData del(HttpServletRequest request,String poiId) {
        if (poiId == null) {
            return Callback.fail("fail", "删除失败");
        }
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return fegin.del(userInfo,poiId);
    }

    @Require
    @ApiOperation("删除所有目的地记录")
    @PostMapping("/delall")
    public JsonData delall(HttpServletRequest request, @ApiParam(name = "城市id") @RequestParam("cityId") String cityId) {
        if (cityId == null){
            return Callback.fail("fail","删除失败");
        }
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return fegin.delall(userInfo,cityId);
    }
}
